{% extends "common/layout_main.html" %}
{% block content %}
<div class="row  border-bottom">
    <div class="col-lg-12">
        <div class="tab_title">
            <ul class="nav nav-pills">
                <li>
                    <a href="{{ url_for('food_page.index') }}">美食列表</a>
                </li>
                <li class="current">
                    <a href="{{ url_for('food_page.category') }}">分类列表</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <form class="form-inline wrap_search">
            <div class="row  m-t p-w-m">
                <div class="form-group">
                    <select name="status" class="form-control inline">
                        <option value="-1">请选择状态</option>
                        <option value="1">正常</option>
                        <option value="0">已删除</option>
                    </select>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-primary search">
                                <i class="fa fa-search"></i> 搜索
                            </button>
                        </span>
                    </div>
                </div>
            </div>
            <hr>
            <div class="row">
                <div class="col-lg-12">
                    <a class="btn btn-w-m btn-outline btn-primary pull-right"
                       href="{{ url_for('food_page.categoryInsert') }}">
                        <i class="fa fa-plus"></i> 分类
                    </a>
                </div>
            </div>

        </form>
        <table class="table table-bordered m-t">
            <thead>
            <tr>
                <th>序号</th>
                <th>分类名称</th>
                <th>状态</th>
                <th>权重</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% if pagination.data_list %}
                {% for item in pagination.data_list %}
            <tr>
                <td>{{ loop.index }}</td>
                <td>{{ item.name }}</td>
                <td>{% if item.status ==1 %}正常{% elif item.status == 0 %}已删除{% endif %}</td>
                <td>{{ item.weight }}</td>
                <td>
                     {%  if item.status == 1 %}
                    <a class="m-l" href="{{ url_for('food_page.categoryEdit') }}?id={{  item.id }}">
                        <i class="fa fa-edit fa-lg"></i>
                    </a>

                    <a class="m-l remove" href="javascript:fun('category-remove',{{ item.id }},{{ pagination.current_page }},{{ condition.status }});">
                        <i class="fa fa-trash fa-lg"></i>
                    </a>
                    {%  else %}
                    <a class="m-l recover" href="javascript:fun('category-recover',{{ item.id }},{{ pagination.current_page }},{{ condition.status }});">
                        <i class="fa fa-rotate-left fa-lg"></i>
                    </a>
                    {% endif %}

                </td>
            </tr>
                {% endfor %}
            {%  else %}
                <tr><td colspan="5">暂无数据</td></tr>
            {% endif %}
            </tbody>
        </table>

        <!--分页代码-->
        <div class="row">
            <div class="col-lg-12">
                <span class="pagination_count" style="line-height: 40px;">共{{ pagination.totals }}条数据 | {{ pagination.total_pages }}页</span>
                <ul class="pagination pagination-sm no-margin pull-right">
                <li><a href="{{ url_for('food_page.category') }}?page={{ pagination.prev_page }}&status={{ condition.status }}">&laquo;</a></li>
                {% if pagination.total_pages <= 15 %}
                    {% for k in pagination.page_range %}
                        {% if pagination.current_page == k %}
                        <li class="active"><a href="{{ url_for('food_page.category') }}?page={{ k }}&status={{ condition.status }}">{{ k }}</a></li>
                        {% else %}
                        <li><a href="{{ url_for('food_page.category') }}?page={{ k }}&status={{ condition.status }}">{{ k }}</a></li>
                        {% endif %}
                    {% endfor %}
                {% else %}
                        <li><a href="javascript:void(0);">...</a></li>
                {% endif %}
                <li><a href="{{ url_for('food_page.category') }}?page={{ pagination.next_page }}&status={{ condition.status }}">&raquo;</a></li>
              </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block js%}
<script>
    var wrap_search = {
		init:function(){
			this.eventBind()
		},
		eventBind:function(){
            $(".wrap_search .search").click(function(){
                $(".wrap_search").submit()
            })
		}
	}

    $(document).ready(function(){
        wrap_search.init();
    })

    function fun(opt,id,page,status){
        var callback = {
            "ok":function(){
                $.ajax({
                    url:"/food/" + opt,
                    type:"POST",
                    data:{"id":id},
                    dataType:"json",
                    success:function(res){
                        var callback = null
                        if(res.code == 200){
                            callback = function(){
                                window.location.href = "/food/category?page="+page +"&status="+status
                            }
                            common_ops.alert(res.msg,callback)
                        }

                        if(res.code == -1){
                            common_ops.alert(res.msg)
                        }
                    }
                })
            },
            "cancel":null
        };
        common_ops.confirm((opt=="category-remove" ? "确定删除吗?" : "确定恢复吗?"),callback)
    }

</script>
{% endblock %}
